package com.home.duy.code.DAO;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.home.Entity.Ban;
import com.home.Entity.ThietBi;
import com.home.System.HibernateUtil;
import com.home.duy.code.Abstract.AbstractDAO;

public class ThietBiDAO extends AbstractDAO {
	private Session session;
	private Transaction trans;
	public ThietBiDAO()
	{
		super();
	}
	
	@Override
	public boolean saveOrUpdate(Object obj) {
		return super.saveOrUpdate(obj);
	}

	@Override
	public boolean delete(Object obj) {
		return super.delete(obj);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public Object findByPk(Class clas, long pk) {
		return super.findByPk(clas, pk);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public List findAll(Class clas) {
		return super.findAll(clas);
	}
	
	public ThietBi findByFirstRecord()
	{
		startOperation();
		ThietBi tb = null;
		try {
			tb = (ThietBi)session.createSQLQuery("SELECT TOP 1* FROM THIETBI").addEntity(ThietBi.class).uniqueResult();
			trans.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
		finally
		{
			session.close();
		}
		return tb;
	}
	private void startOperation()
	{
		session = HibernateUtil.getSessionFactory().openSession();
		trans = session.beginTransaction();
	}
}
